/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.bashsoft.nero.nameparser;

import java.io.IOException;
import java.net.ConnectException;


/**
 *
 * @author nero
 */
public class HttpHelper {    
    public static HtmlPage getHtml(String url, String sport) throws ConnectException {
        try {                 
            java.net.URL link = new java.net.URL("http://stats.sportbox.ru/" + url);             
            java.io.InputStream is = link.openStream();
            try {
                byte b[] = new byte[1024]; 
                int len = 0; 
                java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); 
                try {                   
                    while ((len = is.read(b)) != -1) { 
                        baos.write(b, 0, len);
                    }
                    String html = baos.toString();
                    return new HtmlPage(html, sport);
                }                
                finally {
                    baos.close();
                }                
            }
            finally {
                is.close();
            }
        }  
        catch (java.net.MalformedURLException ex) {
            throw new java.net.ConnectException(ex.getMessage());
        }
        catch (java.io.IOException ex) {
            throw new java.net.ConnectException(ex.getMessage());
        }
    }
}
